package com.xuan.yubi.controller;


import com.xuan.yubi.common.BaseResponse;
import com.xuan.yubi.common.ResultUtils;
import com.xuan.yubi.model.entity.User;
import com.xuan.yubi.model.vo.AiFrequencyVo;
import com.xuan.yubi.service.AiFrequencyService;
import com.xuan.yubi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/aiFrequency")
public class AiFrequencyController {

    @Autowired
    private UserService userService;

    @Autowired
    private AiFrequencyService aiFrequencyService;

    @GetMapping("/free")
    public BaseResponse<Boolean> getAiInvokeCount(HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);

        boolean result = aiFrequencyService.getAiInvokeCount(loginUser.getId());
        return ResultUtils.success(result);
    }

    @GetMapping("/get")
    public BaseResponse<AiFrequencyVo> getAiFrequencyVo(HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);

        AiFrequencyVo aiFrequencyVo = aiFrequencyService.getAiFrequencyVo(loginUser.getId());
        return ResultUtils.success(aiFrequencyVo);
    }
}
